﻿using System;
using System.IO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace FoodRaidersWebAPI.Service
{
    public class FileUpload
    {
        public static String Upload(IFormFile file)
        {
            String path = "http://localhost:5000/";
            String filename = "img/" + file.FileName;
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            using (FileStream fs = File.Create(filename))
            {
                // 复制文件
                file.CopyTo(fs);
                // 清空缓冲区数据
                fs.Flush();
            }

            path += filename;
            return path;
        }
    }
}